package com.example.demo.controller;


import com.example.util.SpringUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurationSupport {

  @Override
  protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    String webRoot = "file:" + SpringUtil.absWebRoot.getAbsolutePath().replaceAll("\\\\", "/") + "/";
    System.out.println(webRoot);
    registry.addResourceHandler("/**")
        .addResourceLocations("file:D:/ideaSpace/yichang/src/main/resources/static/")
        .addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/")
        .addResourceLocations(webRoot);
    super.addResourceHandlers(registry);
  }
}
